const http = require('http')
const url = require('url')
const app = http.createServer()
const { get,post,put,Del } = require('./router/router')

app.on('request',(req,res)=>{
    res.setHeader('Content-type','text/html;charset=utf8')
    res.setHeader('Access-Control-Allow-Origin','*')
    res.setHeader('Access-Control-Allow-Methods','PUT,POST','GET','DELETE','OPTIONS')
    let { pathname } = url.parse(req.url,true)
    if(pathname == '/good' && req.method == 'GET'){
        get(req,res)
    }else if(pathname == '/good' && req.method == 'PUT'){
        put(req,res)
    }else if(pathname == '/good' && req.method == 'DELETE'){
        Del(req,res)
    }else if(pathname == '/good' && req.method == 'POST'){
        post(req.res)
    }
})
app.listen(3001,()=>{
    console.log('服务已启动,端口号3001')
})